package gdonly.top.signin.widgets;

import android.app.Activity;
import android.support.v7.widget.CardView;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.View;
import android.view.ViewGroup;
import android.widget.LinearLayout;
import android.widget.TextView;

import java.util.HashMap;
import java.util.List;

import gdonly.top.signin.R;


/**
 * Created by zhuzhuxia on 16/12/26.
 */
public class SubRecyclerViewAdapter extends RecyclerView.Adapter<ViewHolder> {
    private List<HashMap<String,Object>> mData;
    private Activity context;
    public SubRecyclerViewAdapter(List<HashMap<String,Object>> list,Activity context){
        mData = list;
        this.context=context;
    }
    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View linearLayout= LinearLayout.inflate(parent.getContext(), R.layout.item_schedule, null);
        ViewHolder viewHolder=new ViewHolder(linearLayout,context);
        return viewHolder;
    }


    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {


        if(mData!=null) {
            Log.e("TAG", "settext....");
            holder.stuNameTv.setText((String) mData.get(position).get("stu_name"));
            holder.courseNameTv.setText((String) mData.get(position).get("course_name"));
            holder.dateTv.setText((String) mData.get(position).get("date"));
            holder.stuIdTv.setText((String)mData.get(position).get("stu_id"));

            if((boolean)mData.get(position).get("state") == false){
                holder.stuNameTv.setTextColor(context.getResources().getColor(R.color.light_red));
                holder.stuIdTv.setTextColor(context.getResources().getColor(R.color.light_red));
                holder.courseNameTv.setTextColor(context.getResources().getColor(R.color.light_red));
                holder.dateTv.setTextColor(context.getResources().getColor(R.color.light_red));

            }
            else if((boolean)mData.get(position).get("state") == true){
                holder.stuIdTv.setTextColor(context.getResources().getColor(R.color.light_green));
                holder.stuNameTv.setTextColor(context.getResources().getColor(R.color.light_green));
                holder.courseNameTv.setTextColor(context.getResources().getColor(R.color.light_green));
                holder.dateTv.setTextColor(context.getResources().getColor(R.color.light_green));
            }
        }
    }

    @Override
    public int getItemCount() {
        return mData.size();
    }

}

class ViewHolder extends RecyclerView.ViewHolder{

    public TextView dateTv;
    public TextView stuNameTv;
    public TextView courseNameTv;
    public TextView stuIdTv;
    public CardView cardView;

    private Activity context;


    public ViewHolder(View itemView,Activity context) {
        super(itemView);
        this.context=context;
        cardView = (CardView) itemView.findViewById(R.id.background);
        stuIdTv = (TextView) itemView.findViewById(R.id.stu_id_tv);
        courseNameTv = (TextView) itemView.findViewById(R.id.course_name_tv);
        stuNameTv= (TextView) itemView.findViewById(R.id.stu_name_tv);
        dateTv= (TextView) itemView.findViewById(R.id.date_tv);
    }

}

